package com.woniuxy.project.campus.canteen.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.project.campus.canteen.model.ProductType;
import com.woniuxy.project.campus.canteen.param.AddProductGroupParam;
import com.woniuxy.project.campus.canteen.param.DeleteProductTypeParam;
import com.woniuxy.project.campus.canteen.param.UpdateProductTypeParam;
import com.woniuxy.project.campus.canteen.service.ProductTypeService;
import com.woniuxy.project.campus.canteenModelform.AddProductGroupFrom;
import com.woniuxy.project.campus.canteenModelform.AddProductTypeForm;
import com.woniuxy.project.campus.canteenModelform.DeleteProductTypeForm;
import com.woniuxy.project.campus.canteenModelform.UpdateProductTypeForm;
import com.woniuxy.project.campus.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 猫将军
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/productType")
public class ProductTypeController {


    @Resource
    private ProductTypeService productTypeService;

    //添加商品类型
    @RequestMapping("/addProductGroup")
    public Result addProductGroup(@RequestHeader("token") String token, @RequestBody AddProductGroupFrom form) throws Exception{
        AddProductGroupParam bean = BeanUtil.toBean(form, AddProductGroupParam.class);
        bean.setToken(token);
        productTypeService.addProductGroup(bean);
        return Result.success(null);
    }
    //商户查询商品所有类型
    @ApiOperation(value = "查询所有商品类型")
    @GetMapping("/queryAllProductType")
    public Result queryAllProductType(@RequestHeader("token") String token) throws Exception{
       List<ProductType> list = productTypeService.queryAllProductType(token);
       return Result.success(list);
    }
    //删除商品类型
    @ApiOperation(value = "删除商品类型")
    @PostMapping("/deleteProductType")
    public Result deleteProductType(@RequestHeader("token") String token, @RequestBody DeleteProductTypeForm form) throws Exception{

        DeleteProductTypeParam bean = BeanUtil.toBean(form, DeleteProductTypeParam.class);
        bean.setToken(token);
        productTypeService.deleteProductType(bean);
        return Result.success("删除商品类型成功");
    }
    //修改商品类型
    @ApiOperation(value = "修改商品类型")
    @PostMapping("/updateProductType")
    public Result updateProductType(@RequestHeader("token") String token, @RequestBody UpdateProductTypeForm form) throws Exception{
        UpdateProductTypeParam bean = BeanUtil.toBean(form, UpdateProductTypeParam.class);
        bean.setToken(token);
        productTypeService.updateProductType(bean);
        return Result.success("修改商品类型成功");
    }

    //添加商品类型
    @ApiOperation(value = "添加商品类型")
    @RequestMapping("/addProductType")
    public Result addProductType(@RequestHeader("token") String token, @RequestBody AddProductTypeForm form) throws Exception{
        productTypeService.addProductType(form,token);
        return Result.success("添加商品类型成功");
    }




}

